package com.vincent.template.controller.manage;

import com.vincent.template.commons.base.VctVo;
import com.vincent.template.dto.sys.authgroup.AuthGroupDto;
import com.vincent.template.service.logic.AuthGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Vincent Wang
 * @date 2021/3/25 19:11
 */
@Api(tags = "权限组管理")
@RestController
@RequestMapping("/manage/authGroup")
public class AuthGroupController {
    
    @Autowired
    private AuthGroupService authGroupService;

    @ApiOperation("查询所有权限组")
    @GetMapping
    public List<AuthGroupDto> findAuthGroups() {
        return authGroupService.findAuthGroups();
    }

    @ApiOperation("根据id查询权限组")
    @GetMapping("/{id}")
    public AuthGroupDto findAuthGroupById(@PathVariable("id") Long id) {
        return authGroupService.findAuthGroupById(id);
    }

    @ApiOperation("添加权限组")
    @PostMapping("/create")
    public VctVo<Long> addAuthGroup(@Validated @RequestBody AuthGroupDto authGroupDto) {
        return VctVo.id(authGroupService.addAuthGroup(authGroupDto));
    }

    @ApiOperation("更新权限组")
    @PutMapping("/{id}/update")
    public boolean updateAuthGroup(@PathVariable("id") Long id,
                                   @Validated @RequestBody AuthGroupDto authGroupDto) {
        return authGroupService.updateAuthGroup(id, authGroupDto);
    }

    @ApiOperation("删除权限组")
    @DeleteMapping("/{id}/delete")
    public boolean deleteAuthGroup(@PathVariable("id") Long id) {
        return authGroupService.deleteAuthGroup(id);
    }
    
}
